package lesson08;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class MyThreadPool {
    BlockingQueue<Runnable> queue=new LinkedBlockingDeque<>(100);
    public MyThreadPool(int threadNumber){
        if(threadNumber<=0){
            throw  new IllegalArgumentException("线程数要大于0");
        }
        for (int i = 0; i < threadNumber; i++) {
            Thread thread = new Thread(() -> {
                while (true){
                    try {
                        Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
            }

            });
            thread.start();
        }
    }
    public  void  setRun(Runnable runnable) throws CloneNotSupportedException, InterruptedException {
        if(runnable==null){
            throw  new CloneNotSupportedException("参数异常");
        }
        else queue.put(runnable);
    }

}
